/*
COPYRIGHT (C) 2008 EPISERVER AB

THIS FILE IS PART OF WIKIX.
WIKIX IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

WIKIX IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
YOU SHOULD HAVE RECEIVED A COPY OF THE GNU LESSER GENERAL PUBLIC LICENSE ALONG WITH WIKIX. IF NOT, SEE <HTTP://WWW.GNU.ORG/LICENSES/>.
*/

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.Web.WebControls;
using EPiServer.Research.Wiki.DynamicContent;
using EPiServer.Research.Wiki.Core;

namespace EPiServer.Research.Wiki.Units
{
    public partial class EditedNow : WikiElement
    {
        protected override void CreateProperties()
        {
            PropertyNumber pal = new PropertyNumber(5);
            pal.Name = "Max links to show";
            properties.Add(pal);

        }

        public string EditorName(PageData pd)
        {
            return EditManager.Instance.WhoLocked(pd.PageLink).DisplayName;
        }

        public override void SetProperties(PropertyDataCollection pdc)
        {
            ArticleList.DataSource = EditManager.Instance.ListLockedPages();
            ArticleList.MaxCount = Convert.ToInt32(Properties["Max links to show"].Value);
            ArticleList.DataBind();
        }

        protected string GetTitle(object o)
        {
            PageData pd = (o as PageData);
            if (pd == null)
                return String.Empty;
            if (pd.PageTypeName == WikiManager.WIKIARTICLENAME) return pd.PageName;
            return WikiManager.Instance.GetWikiArticle(pd).PageName + " > " + pd.PageName;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected override string GetAscxUrl()
        {
            return "~/EPiServer.Research.Wiki/Units/EditedNow.ascx";
        }
    }
}